package com.example.love_margin.Mapper;


import com.example.love_margin.Entity.Pet;
import com.example.love_margin.Mapper.configuer.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PetMapper {

    @InsertProvider(type = addPet.class,method = "addPets")
    int addPet(Pet pet);

    @Delete("DELETE FROM pet WHERE pet_id=#{pet_id}")
    int deletePet(int pet_id);

    @DeleteProvider(type = DeleteMany.class,method = "deleteM")
    int deletePets(String sql);

    //通过id进行修改宠物信息
    @UpdateProvider(type = UpdatePet.class, method = "UpOnePet")
    int upOnePet(Pet pet);


    //查询宠物图片
    @Select("SELECT pet_picture FROM pet WHERE pet_id=#{pet_id}")
   String selectPetUrl(int pet_id);

//    //查询宠物图片
//    @Select("SELECT pet_picture FROM pet WHERE pet_id=#{pet_id}")
//    String selectPetOldUrl(int pet_id);

    //查询该宠物是否存在
    @Select("SELECT pet_id FROM pet WHERE pet_id=#{pet_id}")
    String selectPetUrl2(int pet_id);

    //查询多个宠物的图片的地址用以删除
    @SelectProvider(type = SeletPetPicture.class,method = "SelectPetP")
    List<String> selectPetAll(String URL);

    //查询多个宠物的全部信息
    @SelectProvider(type = SeletPetPicture.class,method = "SelectPetP")
    List<Pet> selectPetAllM(String sql);


    //通过id查询单个宠物的所有信息
    @Select("SELECT * FROM pet WHERE pet_id=#{pet_id}")
    Pet selectOnePetAll(int pet_id);

    //查询数据库前十条数据，id自增的时候，是从id最小的开始到第十条最大
    @Select("select * from pet limit 0,10")
    List<Pet> selectTen();

//
    //根据id加一查询后十条数据
    @Select("select * from pet where pet_id >= #{pet_id} order by pet_id asc limit 10")
    List<Pet> selectLast(@Param("pet_id") int pet_id);

    //根据id加一查询后x条数据
    @Select("select * from pet where pet_id >= #{pet_id} order by pet_id asc limit #{num}")
    List<Pet> selectLast2(@Param("pet_id") int pet_id,@Param("num") int num);

    //多条件查询
    //1=1的作用是防止语句就变成了 select * from table where ，这时候查询就会报错
//    @Select("<script>"+
//            "SELECT * FROM pet" +
//            " WHERE 1=1"+
//            "<if test='pet_category!= null'>"+
//            "and pet_category = #{pet_category}"+
//            "</if>"+
//            "<if test='pet_varieties!= null'>"+
//            "and pet_varieties = #{pet_varieties}"+
//            "</if>"+
//            "<if test='pet_sex!= null'>"+
//            "and pet_sex = #{pet_sex}"+
//            "</if>"+
//            "</script>")
//    List<Pet> selectManyKey(@Param("pet_category") String pet_category,@Param("pet_varieties") String pet_varieties,@Param("pet_sex") String pet_sex);

    //多条件查询
    //1=1的作用是防止语句就变成了 select * from table where ，这时候查询就会报错
    @SelectProvider(type = SelectPets.class,method = "selectManyKey")
//    @Select("select * from pet where pet_category=#{pet_category}")
    List<Pet> selectManyKey(String pet_category,String pet_varieties,String pet_sex);


    @SelectProvider(type = SelectPet2.class,method = "selectManyAdmin")
//    @Select("select * from pet where pet_category=#{pet_category}")
    List<Pet> selectManyKeyAd(String pet_category,String pet_varieties,String pet_sex,String key);

    //多条件加关键词加分页
    @SelectProvider(type = SelectPet2.class,method = "selectManyAdmin")
    List<Pet> selectManyPage(String pet_category, String pet_varieties, String pet_sex, String key);



}
